package com.itaming.lycheeframework.security.token;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * Token类型
 *
 * @author A.Ming
 */
@Getter
@RequiredArgsConstructor
public enum TokenType {

    /**
     * 访问令牌
     */
    ACCESS("access"),

    /**
     * 刷新令牌
     */
    REFRESH("refresh"),

    ;

    private final String code;

    /**
     * 根据code获取枚举
     *
     * @param code code
     * @return TokenType
     */
    public static TokenType of(String code) {
        if (code != null) {
            for (TokenType e : values()) {
                if (e.getCode().equalsIgnoreCase(code)) {
                    return e;
                }
            }
        }

        return null;
    }

}
